﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CoursePack;
using Heap;

namespace Scheduler
{
    public class ConstraintManager
    {
        #region Data
        private List<Constraint> m_Constraints;
        #endregion


        public ConstraintManager()
        {
            this.m_Constraints = new List<Constraint>();
        }

        public bool AddConstraint(Constraint _Constraint)
        {
            this.m_Constraints.Add(_Constraint);
            return true;
        }

        public CourseConstraintKey EvaluateCourse(Course _Course,int _Type)
        {
            int TotalConstraint = this.m_Constraints.Count;
            CourseConstraintKey key = new CourseConstraintKey(TotalConstraint, _Type);

            Constraint constraint;
            TimeConstraint cons;

            for (int i = 0; i < TotalConstraint; i++)
            {
                constraint = this.m_Constraints[i];

                // Timeconstraint
                if (constraint.GetType() == typeof(TimeConstraint))
                {
                    cons = (TimeConstraint)constraint;

                    key[i] = cons.CheckConstraint(_Course);
                }
            }

            return key;
        }

        public ConstraintKey EvaluateSchedule(Schedule _Schedule, int _Type)
        {

            ScheduleConstraintKey constraintKey = new ScheduleConstraintKey(_Schedule.Courses.Count,_Type);


            for (int i = 0; i < _Schedule.Courses.Count;i++)
            {
                constraintKey[i] = this.EvaluateCourse(_Schedule.Courses[i], 0);

            }

            return constraintKey;
           
        }
        #region Accessors
        public List<Constraint> Constraints
        {
            get { return this.m_Constraints; }
        }
        #endregion
    }
}
